﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace EGS.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class DepartmentController : ControllerBase
    {
        private readonly EGSDbContext db;
        public DepartmentController(EGSDbContext context)
        {
            db = context;
        }
        [HttpGet("GetAll")]
        public List<EGS_Department> GetAll()
        {
            return db.Department.ToList();
        }
        [HttpGet("{id}")]
        public EGS_Department? GetEGS_PayfeesById(Guid id)
        {
            EGS_Department? dep = new EGS_Department();
            dep = db.Department.Where(e => e.ID == id).FirstOrDefault();
            return dep;
        }
        [HttpPost]
        public Result AddDepartment([FromBody] EGS_Department dep)
        {
            Result result = new Result();
            db.Department.Add(dep);
            result.Data = db.SaveChanges();
            return result;
        }
        [HttpDelete]
        public Result DelDepartment(Guid Id)
        {
            Result result = new Result();
            EGS_Department? dep = new EGS_Department();
            dep = db.Department.Where(w => w.ID == Id).FirstOrDefault();
            result.Data = db.SaveChanges();

            return result;
        }
        [HttpPut]
        public Result UpDepartment([FromBody] EGS_Department dep)
        {
            Result result = new Result();
            db.Department.Update(dep);
            result.Data = db.SaveChanges();

            return result;
        }
       
    }
}
